<template>
	<view class="container">
		<view class="top" style="width: 710rpx;height: 76rpx;background-color: #FFF;padding-top: 10rpx;padding-left: 20rpx;padding-right: 20rpx;">
			<u-search placeholder="请输入券名" v-model="itemName" @search='search' @custom='search'></u-search>
		</view>
		<view class="VIP"
		v-for="(item, index) in dataList" :key='index'
		style="padding: 30rpx;margin-top: 10rpx;background-color: #fff;">
			<view class="lesseeName" style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
				<view style="font-size: 32rpx;font-weight: bold;color: #FFF;">{{item.memberCartModel.name}}</view>
				<view @click="operateAction('look', item)"
				style="width: 180rpx;height: 60rpx;margin-left: 10rpx;display: flex;flex-direction: row;align-items: center;justify-content: center;font-size: 28rpx;border-radius: 8rpx;color: #FFF;background-color: #000;">
					查看详情 >
				</view>
			</view>
			<view class="phone" style="margin-top: 30rpx;color: #FFF;font-size: 26rpx;">
				{{item.memberCartModel.memberCartIntr}}
			</view>
		</view>
		<view style="padding-top: 300rpx;" v-if='showEmpty'>
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	import { userCart } from '@/api/userCart.js'
	export default{
		components: {},
		data() {
			return {
				page: 1,
				size: 20,
				dataList: [],
				showEmpty: false,
				isLastPage: false,
				itemName: '',
				userInfo: {}
			}
		},
		onLoad() {
		},
		onShow() {
			this.userInfo = this.$storage.getStorageDataSync(this.$store.state.userInfo)
			this.getDataList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.getDataList()
		},
		onReachBottom() {
			if(this.isLastPage) {
				return
			}
			this.getDataList()
		},
		methods:{
			search(){
				this.page = 1
				this.getDataList()
			},
			operateAction(scene, val) {
				console.log('事件', scene, val)
				switch (scene) {
					case 'look':
						this.$Router.push({
							name: 'vipCartDetail',
							params: {
								userCartId: val.id
							}
						})
						break;
					default:
						break;
				}
			},
			getDataList() {
				var params = {
					page: this.page,
					size: this.size,
					name: this.itemName,
					user: this.userInfo.id,
				}
				userCart.getUserCartList(params).then(res => {
					uni.stopPullDownRefresh();
					if (res.data.code == 10000) {
						if(this.page == 1){
							this.dataList = []
						}
						var list = res.data.data.list
						this.dataList = [...this.dataList, ...list]
						this.showEmpty = this.dataList.length<1
						if (res.data.data.next) {
							this.page += 1
						} else {
							this.isLastPage = true
						}
					}
				})
			},
			ckeckCoupon(val){
				var params = {
					lesseeId: val.lessee
				}
				if(val.isHasGet){
					params.couponId = val.couponModel.id
				}else{
					params.privilegeId = val.id
				}
				this.$Router.push({
					name: 'qrCode',
					params: params
				})
			},
			// 领券
			getCouponAction(val, index){
				privilege.getCoupon({
					privilegeId: val.id
				}).then(res => {
					if(res.data.code == 10000){
						var couponModel = res.data.data
						uni.showToast({
							title: '领券成功',
							icon: 'success'
						})
						this.$set(val, 'isHasGet', 1)
						val.remainCount--
						this.$set(val, 'couponModel', couponModel)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.VIP{
		width: 658rpx;
		height: 200rpx;
		margin-left: 16rpx;
		border-radius: 16rpx;
		background-image: linear-gradient(30deg, #4d41d3, #9da5f9);
	}
</style>
